package com.valley.dream.tihai.model.dto;

import android.os.Parcel;
import android.os.Parcelable;

import lombok.Data;

@Data
public class ProblemParcelable implements Parcelable {

    private Integer userId;

    private Integer typeId;

    public ProblemParcelable() {
    }

    public ProblemParcelable(Integer userId, Integer typeId) {
        this.userId = userId;
        this.typeId = typeId;
    }

    protected ProblemParcelable(Parcel in) {
        if (in.readByte() == 0) {
            userId = null;
        } else {
            userId = in.readInt();
        }
        if (in.readByte() == 0) {
            typeId = null;
        } else {
            typeId = in.readInt();
        }
    }

    public static final Creator<ProblemParcelable> CREATOR = new Creator<ProblemParcelable>() {
        @Override
        public ProblemParcelable createFromParcel(Parcel in) {
            return new ProblemParcelable(in);
        }

        @Override
        public ProblemParcelable[] newArray(int size) {
            return new ProblemParcelable[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (userId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(userId);
        }
        if (typeId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(typeId);
        }
    }
}
